using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPCoco.Tasks
{
    public class FiniteTime : Task
    {
        public FiniteTime(float duration)
        {
            Duration = duration;
        }

        float duration;

        public float Duration
        {
            get { return duration; }
            set 
            {
                if (value < float.Epsilon)
                    value = 0.001f;
                duration = value;
            }
        }

        bool ended = false;

        public override void Initialize()
        {
            base.Initialize();
            ended = false;
        }

        public override void Update(float time)
        {
            if (time > duration || time < 0)
                ended = true;
            else ended = false;
        }

        public override bool HasEnded()
        {
            return ended;
        }

        public override void Finish()
        {
            Update(duration);   
        }

        public override Task Clone()
        {
            return new FiniteTime(duration);
        }

        public override Task Reverse()
        {
            return new FiniteTime(duration);
        }
    }
}
